import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
// import { openGoodsDeviceDialog } from '@/views/equipment-goods-manage/components/overview-info-dialog';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getDevIotLocation } from '@gis/lib/api';

const typeCodeEnum = {
  D0114_1: 'yg', // 烟感
  D0114_2: 'mc', // 门磁
  D0114_3: 'jg', // 井盖
  D0114_4: 'ljt', // 垃圾桶
  D0114_5: 'dqhz', // 电气火灾
  D0114_9: 'yyjc', // 油烟检测
  D0114_11: 'yijianbj', // 一键报警
  D0114_12: 'gkpw', // 高空抛物
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick() {
    // openGoodsDeviceDialog(this.data);
  }
}

export default class Wlsb extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      area_code: area_code,
    };
    const data = await handleCommonRes(getDevIotLocation, params);
    return data
      .filter((item) => item.longitude && item.latitude)
      .map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
